# Copyright 2024 Ant Group Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@yacl//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test")

package(default_visibility = ["//visibility:public"])

test_suite(
    name = "gemini_rlwe_tests",
)

yacl_cc_library(
    name = "gemini_rlwe",
    srcs = [
        "a2h.cc",
        "matvec.cc",
    ],
    hdrs = [
        "a2h.h",
        "matvec.h",
    ],
    deps = [
        ":lwe_decryptor",
        ":lwe_types",
        ":lwe_util",
        ":modswitch",
        ":poly_encoder",
        "@com_github_microsoft_seal//:seal",
    ],
)

yacl_cc_library(
    name = "poly_encoder",
    srcs = [
        "poly_encoder.cc",
    ],
    hdrs = [
        "poly_encoder.h",
    ],
    deps = [
        ":lwe_types",
        ":modswitch",
    ],
)

yacl_cc_library(
    name = "lwe_decryptor",
    srcs = [
        "lwe_decryptor.cc",
    ],
    hdrs = [
        "lwe_decryptor.h",
    ],
    deps = [
        ":lwe_types",
        ":modswitch",
    ],
)

yacl_cc_library(
    name = "lwe_util",
    srcs = [
        "util.cc",
    ],
    hdrs = [
        "util.h",
    ],
    deps = [
        ":lwe_types",
    ],
)

yacl_cc_library(
    name = "lwe_types",
    srcs = [
        "lwe_ct.cc",
        "lwe_secret_key.cc",
    ],
    hdrs = [
        "lwe_types.h",
    ],
    deps = [
        ":modswitch",
        "@com_github_microsoft_seal//:seal",
        "@yacl//yacl/base:buffer",
        "@yacl//yacl/base:byte_container_view",
    ],
)

yacl_cc_library(
    name = "modswitch",
    srcs = ["modswitch_helper.cc"],
    hdrs = ["modswitch_helper.h"],
    deps = [
        "@com_github_microsoft_seal//:seal",
        "@yacl//yacl/base:exception",
        "@yacl//yacl/base:int128",
    ],
)

yacl_cc_test(
    name = "modswitch_helper_test",
    srcs = ["modswitch_helper_test.cc"],
    deps = [
        ":modswitch",
        "@com_google_googletest//:gtest",
    ],
)

yacl_cc_test(
    name = "rlwe_2_lwe_test",
    srcs = ["rlwe_2_lwe_test.cc"],
    deps = [
        ":gemini_rlwe",
    ],
)

yacl_cc_test(
    name = "matvec_test",
    srcs = ["matvec_test.cc"],
    deps = [
        ":gemini_rlwe",
    ],
)

yacl_cc_test(
    name = "a2h_test",
    srcs = ["a2h_test.cc"],
    deps = [
        ":gemini_rlwe",
    ],
)
